package com.sanshui.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sanshui.base.BaseResponse;
import com.sanshui.base.ResultUtils;
import com.sanshui.model.entity.Emoji;
import com.sanshui.service.EmojiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.xml.transform.Result;

/**
 * @author Administrator
 */
@RestController
@RequestMapping(value = "/emoji")
@Api(tags = "表情的增删改查")
public class EmojiController {

    @Autowired
    private EmojiService emojiService;

    @ApiOperation("表情的添加")
    @RequestMapping(value = "savaEmoji",method = RequestMethod.POST)
    public BaseResponse<String> addEmoji(Emoji emoji){

        System.out.println(emoji.getId());
        if (emoji == null){
            ResultUtils.error(40000,"参数为空");
        }
        emojiService.save(emoji);
        return ResultUtils.success(emoji.getId());
    }

    @ApiOperation("表情的修改")
    @RequestMapping(value = "updateEmoji",method = RequestMethod.PUT)
    public BaseResponse<Boolean> updateEmoji(Emoji emoji){

        if (emoji == null || emoji.getId() == null){
            ResultUtils.error(40000,"参数为空");
        }
        return ResultUtils.success(emojiService.updateById(emoji));
    }

    @ApiOperation("表情的删除")
    @RequestMapping(value = "deleteEmoji",method = RequestMethod.DELETE)
    public BaseResponse<Boolean> deleteEmoji(String id){
        if (id == null && ("").equals(id)){
            ResultUtils.error(40000,"参数为空");
        }
        return ResultUtils.success(emojiService.removeById(id));
    }

    @ApiOperation("表情的查询")
    @RequestMapping(value = "getEmoji",method = RequestMethod.GET)
    public BaseResponse<IPage<Emoji>> getEmoji(Emoji emoji){
        QueryWrapper<Emoji> emojiQueryWrapper = new QueryWrapper<>(emoji);
        return ResultUtils.success(emojiService.page(new Page<>(1,10),emojiQueryWrapper));
    }
}
